<!DOCTYPE HTML>
<html lang="en" >
    
    <head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>es6 | 个人笔记</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-expandable-chapters-interactive/expandable-chapters.css">
        
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-search/search.css">
        
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../../md/js/安装babel.html" />
    
    
    <link rel="prev" href="../../md/js/try-catch语句.html" />
    

        
    </head>
    <body>
        
        
    <div class="book"
        data-level="3.7"
        data-chapter-title="es6"
        data-filepath="md/js/jses6.md"
        data-basepath="../.."
        data-revision="Fri Sep 14 2018 16:41:08 GMT+0800 (中国标准时间)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        Introduction
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="md/html/HTML5.html">
            
                
                    <a href="../../md/html/HTML5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        HTML介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2" data-path="md/css/CSS笔记.html">
            
                
                    <a href="../../md/css/CSS笔记.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        css笔记
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3" data-path="md/js/js基础.html">
            
                
                    <a href="../../md/js/js基础.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        JavaScript
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="md/js/js数据类型的转换.html">
            
                
                    <a href="../../md/js/js数据类型的转换.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        数据类型
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="md/js/js运算符.html">
            
                
                    <a href="../../md/js/js运算符.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        运算符
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.2.1" data-path="md/js/js赋值运算符.html">
            
                
                    <a href="../../md/js/js赋值运算符.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.1.</b>
                        
                        赋值运算符
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2.2" data-path="md/js/js比较运算符.html">
            
                
                    <a href="../../md/js/js比较运算符.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.2.</b>
                        
                        比较运算符
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2.3" data-path="md/js/js逻辑操作符.html">
            
                
                    <a href="../../md/js/js逻辑操作符.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.3.</b>
                        
                        逻辑操作符
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2.4" data-path="md/js/js条件运算符.html">
            
                
                    <a href="../../md/js/js条件运算符.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.4.</b>
                        
                        条件运算符
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2.5" data-path="md/js/js位运算符.html">
            
                
                    <a href="../../md/js/js位运算符.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.5.</b>
                        
                        位运算符
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2.6" data-path="md/js/js条件语句.html">
            
                
                    <a href="../../md/js/js条件语句.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.6.</b>
                        
                        条件语句
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="md/js/js循环.html">
            
                
                    <a href="../../md/js/js循环.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        循环
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.3.1" data-path="md/js/jswhile循环.html">
            
                
                    <a href="../../md/js/jswhile循环.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.1.</b>
                        
                        while循环
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3.2" data-path="md/js/jsfor循环.html">
            
                
                    <a href="../../md/js/jsfor循环.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.2.</b>
                        
                        for循环
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3.3" data-path="md/js/js多层循环.html">
            
                
                    <a href="../../md/js/js多层循环.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.3.</b>
                        
                        多层循环
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="md/js/js函数.html">
            
                
                    <a href="../../md/js/js函数.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.4.</b>
                        
                        函数
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.5" data-path="md/js/js冒泡排序.html">
            
                
                    <a href="../../md/js/js冒泡排序.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.5.</b>
                        
                        冒泡排序
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.6" data-path="md/js/try-catch语句.html">
            
                
                    <a href="../../md/js/try-catch语句.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.6.</b>
                        
                        try-catch语句
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="3.7" data-path="md/js/jses6.html">
            
                
                    <a href="../../md/js/jses6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.7.</b>
                        
                        es6
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.7.1" data-path="md/js/安装babel.html">
            
                
                    <a href="../../md/js/安装babel.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.7.1.</b>
                        
                        安装babel(es6转es5)
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.8" data-path="md/js/js数组对象.html">
            
                
                    <a href="../../md/js/js数组对象.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.8.</b>
                        
                        数组对象
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" data-path="md/js/js笔记.html">
            
                
                    <a href="../../md/js/js笔记.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        js大佬de笔记
                    </a>
            
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    Published with GitBook
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../../" >个人笔记</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h3 id="es6&#xFF1A;&#x662F;ecmascript&#x7684;&#x7B2C;&#x516D;&#x4E2A;&#x7248;&#x672C;&#x7684;&#x7248;&#x672C;&#x53F7;&#x3002;">es6&#xFF1A;&#x662F;ECMAScript&#x7684;&#x7B2C;&#x516D;&#x4E2A;&#x7248;&#x672C;&#x7684;&#x7248;&#x672C;&#x53F7;&#x3002;</h3>
<p>es6:&#x58F0;&#x660E;&#x4E00;&#x4E2A;&#x53D8;&#x91CF;&#xFF1A;let,let&#x4E0D;&#x5B58;&#x5728;&#x58F0;&#x660E;&#x63D0;&#x524D;&#x3002; es5:&#x58F0;&#x660E;&#x4E00;&#x4E2A;&#x53D8;&#x91CF;&#xFF1A;var&#x3002; window&#x5BF9;&#x8C61;&#x6307;&#x7684;&#x5C31;&#x662F;&#x6253;&#x5F00;&#x7684;&#x6D4F;&#x89C8;&#x5668;&#x7A97;&#x53E3;&#x3002;</p>
<ul>
<li>&#x901A;&#x8FC7;let&#x58F0;&#x660E;&#x7684;&#x5168;&#x5C40;&#x53D8;&#x91CF;&#x4E0D;&#x4F1A;&#x6302;&#x8F7D;&#x5728;window&#x5BF9;&#x8C61;&#x4E0B;&#x3002;&#x4E0D;&#x80FD;&#x91CD;&#x590D;&#x58F0;&#x660E;&#x540C;&#x4E00;&#x4E2A;&#x53D8;&#x91CF;&#x3002;</li>
<li>es6&#x65B0;&#x589E;&#x58F0;&#x660E;&#x53D8;&#x91CF;&#x7684;&#x65B9;&#x5F0F;&#xFF1A;&#x89E3;&#x6784;&#x8D4B;&#x503C;</li>
</ul>
<pre><code>        &#x6BD4;&#x5982;&#xFF1A;let [a,b&#xFF0C;c] = [0,1,&quot;&#x6211;&#x662F;&#x5B57;&#x7B26;&#x4E32;&quot;];//&#x7528;var&#x4E5F;&#x53EF;&#x4EE5;
        console.log(a);//0
</code></pre><pre><code>            let str = &quot;&#x6211;&#x662F;&#x901A;&#x8FC7;let&#x5B57;&#x7B26;&#x4E32;&quot;;
            let [a,b,c] = [0,1,&quot;string&quot;]
            console.log(str);
            console.log(c);
            //console.log(window.str);//undefined
</code></pre><ul>
<li>&#x901A;&#x8FC7;var&#x6765;&#x58F0;&#x660E;&#x7684;&#x53D8;&#x91CF;&#x4F1A;&#x6709;&#x58F0;&#x660E;&#x63D0;&#x524D;&#x7684;&#x6548;&#x679C;&#x3002;</li>
<li>&#x901A;&#x8FC7;var&#x58F0;&#x660E;&#x7684;&#x5168;&#x5C40;&#x53D8;&#x91CF;&#x4F1A;&#x81EA;&#x52A8;&#x6302;&#x8F7D;&#x5230;window&#x5BF9;&#x8C61;&#x4E0B;&#xFF0C;&#x6210;&#x4E3A;window&#x5BF9;&#x8C61;&#x4E0B;&#x7684;&#x4E00;&#x4E2A;&#x5C5E;&#x6027;&#x3002;</li>
</ul>
<pre><code>            console.log(str1);//undefined
            var str1 = &quot;&#x6211;&#x662F;&#x901A;&#x8FC7;var&#x6765;&#x58F0;&#x660E;&#x7684;&#x53D8;&#x91CF;&quot;;
            console.log(str1);//&#x6211;&#x662F;&#x901A;&#x8FC7;var&#x6765;&#x58F0;&#x660E;&#x7684;&#x53D8;&#x91CF;
            console.log(window.str1);
</code></pre><ul>
<li>&#x5728;es5&#x4E2D;&#x6709;&#x5168;&#x5C40;&#x53D8;&#x91CF;&#x548C;&#x5C40;&#x90E8;&#x53D8;&#x91CF;</li>
<li><p>es5&#xFF1A;&#x5168;&#x5C40;&#x4F5C;&#x7528;&#x57DF;&#x548C;&#x5C40;&#x90E8;&#x4F5C;&#x7528;&#x57DF;</p>
</li>
<li><p>es6&#x65B0;&#x589E; &#x2014;&#x2014; &#x53EB;&#x5757;&#x7EA7;&#x4F5C;&#x7528;&#x57DF;(&#x53EA;&#x6709;&#x901A;&#x8FC7;let&#x58F0;&#x660E;&#x624D;&#x4F1A;&#x6709;)&#xFF0C;&#x5B9A;&#x4E49;&#x5728;&#x4EE3;&#x7801;&#x5757;{}&#x5185;&#x7684;&#x53EB;&#x5757;&#x7EA7;&#x4F5C;&#x7528;&#x57DF;</p>
</li>
<li><p>&#x53D8;&#x91CF;&#x7684;&#x4F5C;&#x7528;&#x57DF;:&#x6307;&#x7684;&#x662F;&#x53D8;&#x91CF;&#x7684;&#x4F5C;&#x7528;&#x8303;&#x56F4;&#xFF0C;&#x53EF;&#x5206;&#x4E3A;&#x5168;&#x5C40;&#x4F5C;&#x7528;&#x57DF;&#x548C;&#x5C40;&#x90E8;&#x4F5C;&#x7528;&#x57DF;&#x3002;</p>
</li>
<li>&#x5168;&#x5C40;&#x4F5C;&#x7528;&#x57DF;&#x6307;&#x7684;&#x662F;&#x53D8;&#x91CF;&#x5728;&#x5168;&#x5C40;&#x8303;&#x56F4;&#x5185;&#x90FD;&#x53EF;&#x8C03;&#x7528;&#xFF08;&#x5373;&#x5168;&#x5C40;&#x53D8;&#x91CF;&#xFF09;</li>
<li>&#x5C40;&#x90E8;&#x4F5C;&#x7528;&#x57DF;&#x6307;&#x7684;&#x662F;&#x5C40;&#x90E8;&#x53D8;&#x91CF;&#x7684;&#x4F5C;&#x7528;&#x8303;&#x56F4;&#xFF08;&#x5373;&#x5728;&#x51FD;&#x6570;&#x91CC;&#x9762;&#xFF09;&#x3002;</li>
</ul>
<pre><code>            var isCheck = true;
            if(isCheck){
                var j=2;
                let i=10;
            }
            console.log(j);
            console.log(i);

            for(var i = 0;i&lt;3;i++){
                var i = 2;
                console.log(i);//1&#x4E2A;2
            }
            console.log(i);//3
</code></pre><ul>
<li>&#x901A;&#x8FC7;let&#x58F0;&#x660E;&#x7684;&#x53D8;&#x91CF;&#x5728;&#x5FAA;&#x73AF;&#x91CC;&#x9762;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x5C0F;&#x62EC;&#x53F7;&#x548C;&#x5927;&#x62EC;&#x53F7;&#x5206;&#x522B;&#x5B58;&#x5728;&#x4E0D;&#x540C;&#x7684;&#x4F5C;&#x7528;&#x57DF;,&#x5C0F;&#x62EC;&#x53F7;&#x53EB;&#x7236;&#x4F5C;&#x7528;&#x57DF;&#xFF0C;&#x5927;&#x62EC;&#x53F7;&#x53EB;&#x5B50;&#x4F5C;&#x7528;&#x57DF;</li>
</ul>
<pre><code>            for(let k=0;k&lt;3;k++){
                let k = 2;
                console.log(k);//3&#x4E2A;2
            }
            //console.log(k);

            var x = &quot;1&quot;;
            var x = &quot;3&quot;;
            console.log(x);

            let y = &quot;2&quot;;
            y = &quot;4&quot;;//&#x4E0D;&#x4F1A;&#x62A5;&#x9519;
            //let y = &quot;4&quot;;&#x62A5;&#x9519;
            console.log(y);//&#x62A5;&#x9519;&#xFF0C;&#x8BED;&#x6CD5;&#x9519;&#x8BEF;&#xFF0C;y&#x5DF2;&#x7ECF;&#x88AB;&#x58F0;&#x660E;
</code></pre><ul>
<li>&#x5E38;&#x91CF;:es6&#x53EF;&#x4EE5;&#x901A;&#x8FC7;const&#x5173;&#x952E;&#x8BCD;&#x6765;&#x58F0;&#x660E;&#x4E00;&#x4E2A;&#x5E38;&#x91CF;</li>
<li>&#x5E38;&#x91CF;&#x662F;&#x4E0D;&#x53EF;&#x4EE5;&#x6539;&#x53D8;&#x7684;,&#x53D8;&#x91CF;&#x662F;&#x53EF;&#x4EE5;&#x6539;&#x53D8;&#x7684;</li>
</ul>
<pre><code>            const num = 123;
            //num = &quot;456&quot;;Assignment to constant variable.
            console.log(num);
</code></pre><ul>
<li>&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x6807;&#x8BC6;&#x7B26;&#xFF1A;&quot;&quot; / &apos;&apos; / ``(&#x53CD;&#x5355;&#x5F15;&#x53F7;)</li>
</ul>
<pre><code>            var str3 = `&#x6211;&#x662F;&#x5B57;&#x7B26;&#x4E32;`;
            console.log(typeof(str3));

            var str4 = &quot;&#x6211;&#x662F;&#x6D4B;&#x8BD5;&#x5B57;&#x7B26;&#x4E32;&#x62FC;&#x63A5;&#x7684;&quot;;
            document.write(&quot;&lt;h1&gt;&quot;+str4+&quot;&lt;/h1&gt;&quot;);
            //es6&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x62FC;&#x63A5;&#x65B9;&#x6CD5;&#xFF1A;&#x53D8;&#x91CF;&#x8981;&#x7528;&#x4E00;&#x4E2A;&#x7F8E;&#x5143;&#x7B26;&#x53F7;&#x548C;&#x5927;&#x62EC;&#x53F7;&#x5305;&#x88F9;&#x8D77;&#x6765;
            document.write(`&lt;h1&gt;${str4}&lt;/h1&gt;`);
</code></pre><ul>
<li>&#x5F53;&#x6211;&#x4EEC;&#x4F20;&#x5165;&#x7684;&#x53C2;&#x6570;&#x4E0D;&#x5B9A;&#x7684;&#x65F6;&#x5019;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;...name &#x6765;&#x88C5;&#x8F7D;,&#x5176;&#x4F59;&#x7684;&#x53C2;&#x6570;&#xFF0C;&#x5982;&#x4E0B;es6&#x51FD;&#x6570;&#xFF1A;</li>
</ul>
<pre><code>            function es6(num1,num2,...other){
                console.log(num1,num2,other);
            }
            es6(1,2,3,4,5);    

            //es6&#x53EF;&#x4EE5;&#x7ED9;&#x51FD;&#x6570;&#x7684;&#x53C2;&#x8BBE;&#x7F6E;&#x9ED8;&#x8BA4;&#x503C;
            function myFun(num1=3,num2=2){
                console.log(num1,num2);
            }
            myFun(10);
</code></pre><ul>
<li>es6&#x7684;&#x7BAD;&#x5934;&#x51FD;&#x6570;,&#x662F;&#x533F;&#x540D;&#x51FD;&#x6570; &#x7B2C;&#x4E00;&#x79CD;&#x5F62;&#x5F0F;</li>
</ul>
<pre><code>          var fun = () =&gt; console.log(123);
          fun();
          //    &#x2193;&#x4E0A;&#x9762;&#x7684;&#x7BAD;&#x5934;&#x51FD;&#x6570;&#x76F8;&#x5F53;&#x4E8E;&#x4E0B;&#x9762;&#x7684;&#x666E;&#x901A;&#x51FD;&#x6570;
          function fun(){
              console.log(123);
          }
          fun();
</code></pre><p>&#x7B2C;&#x4E8C;&#x79CD;&#x5F62;&#x5F0F;&#xFF08;&#x591A;&#x4E2A;&#x53C2;&#x6570;&#xFF09;</p>
<pre><code>          var func = (num1,num2) =&gt;{
              return num1+num2;
          }
          console.log(func(3,5));

          //&#x7B2C;&#x4E09;&#x79CD;&#x5F62;&#x5F0F;&#xFF08;num&#x4EE3;&#x8868;&#x51FD;&#x6570;&#x7684;&#x53C2;&#x6570;&#xFF09;
          var funct = num =&gt; {
              console.log(num);
          }
          funct(1);
</code></pre>
                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../../md/js/try-catch语句.html" class="navigation navigation-prev " aria-label="Previous page: try-catch语句"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../../md/js/安装babel.html" class="navigation navigation-next " aria-label="Next page: 安装babel(es6转es5)"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../../gitbook/app.js"></script>

    
    <script src="../../gitbook/plugins/gitbook-plugin-expandable-chapters-interactive/expandable-chapters.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-search/lunr.min.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-search/search.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-livereload/plugin.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"expandable-chapters-interactive":{},"highlight":{},"search":{"maxIndexSize":1000000},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"livereload":{}};
    gitbook.start(config);
});
</script>

        
    </body>
    
</html>
